;

(function (call) {
    var main = {
        userInfo:"",
        submitFunData:{},
        defalutData:{},
        submitData:{},
        defaultYbData:{},
        autoWarnLevel: {},
        init: function () {
            this.bindEvt();
            this.initView();
        },
        initView: function () {
            var userInfo = $("#userInfo").data('info');
            this.userInfo = userInfo;
            this.getWarnSetProduct();
            this.queryAutoWarnLevel();
        },
        async queryAutoWarnLevel() {
            let res = await $.ajax({
                type: 'GET',
                url: 'shortWarn/autoStation/queryAutoWarnLevel',
            });
            console.log('queryAutoWarnLevel res======>', res);
            if (res.code === 200) {
                this.autoWarnLevel = res.data;
            }
        },
        //弹出框内容
        alert: function (info) {
            $.dialogMaster({
                "type": 'tip',
                "info": info
            });
        },
        bindEvt: function () {
            var that = this;
            //关闭弹框
            $(".setMain .close").click(function () {
                $("#modal_set").remove();
                $("#set").removeClass("active");
            });
            //关闭弹框
            //绑定展示切换的事件
            $(".singleProduct .showtype").each(function (index) {
                $(this).click(function () {
                    $(this).toggleClass("active");
                })
            })
            $(".highSet_content_types div").each(function(){
                $(this).unbind("click").bind("click",function(){
                    $(".highSet_content_types div").removeClass("active");
                    $(this).addClass("active");
                    $(".highSet_content_main >div").hide();
                    $(".highSet_content_main >div").eq($(this).index()).show();
                })
            })
            //绑定基础警戒的确定
            $(".setMain .submitBtn").unbind("click").bind("click",function () {
                that.clickSubmitFunData();
            })
            $(".setMain .top_close").draggable({container: '#modal_set'});
            var obj = $("#modal_set .highSet").clone();
            $(".highSet").remove();
            $("#modal_set").after(obj);
            var obj1 = $("#modal_set .highYbSet").clone();
            $(".highYbSet").remove();
            $("#modal_set").after(obj1);
            that.setDrag($("#hightSet .top_close"));
            that.setDrag($("#hightYbSet .top_close"))
            $("#set").bind("click",function () {
                $(".highSet").remove();
                $(".hightYbSet").remove();
            })
        },


        setDrag:function(obj){
            obj.unbind("mousedown").bind("mousedown",function(e){
                var oEvent = e || event;
                var oCY = oEvent.clientY, oCX = oEvent.clientX;
                var $panel = $(this).parent("div").parent("div");
                var left = Number($panel.css("left").replace("px","")), top = Number($panel.css("top").replace("px",""));
                $("body").unbind("mousemove").bind("mousemove",function(e){
                    var nowEvent = e || event;
                    var now_mY = nowEvent.clientY-oCY,now_mX = nowEvent.clientX-oCX;
                    var left_ = left+now_mX, top_ = top+now_mY;
                    $panel.css({"left":left_,"top":top_});
                    oEvent = nowEvent;
                }).bind("mouseup",function(e){
                    obj.unbind('mouseup');
                    $("body").unbind("mousemove");
                });
            });
        },
        getWarnSetProduct1:function(){
            var that = this;
            var $firstObj = $(".firstWarn .warnContnt");
            $firstObj.empty();
            var $secondObj = $(".secondWarn .warnContnt");
            $secondObj.empty();
            let res = {"isSuccess":true,"message":null,"code":"200","data":[{"warn_pro_id":"S_RAIN10M","is_email":1,"is_flick":1,"maketime":1752339638000,"orderid":5,"area_code":"12","is_voice":1,"flick_time":3,"area_type":1,"warn_name":"10分钟降水","voicecode":"1","warn_type":1,"is_note":1,"status":1},{"warn_pro_id":"S_RAIN1","is_email":1,"is_flick":0,"maketime":1752339638000,"orderid":11,"area_code":"12","is_voice":0,"flick_time":3,"area_type":1,"warn_name":"1小时降水","voicecode":"1","warn_type":1,"is_note":1,"status":0},{"warn_pro_id":"S_RAIN3","is_email":1,"is_flick":0,"maketime":1752339638000,"orderid":21,"area_code":"12","is_voice":0,"flick_time":3,"area_type":1,"warn_name":"3小时降水","voicecode":"1","warn_type":1,"is_note":1,"status":0},{"warn_pro_id":"S_GALE","is_email":1,"is_flick":0,"maketime":1752339638000,"orderid":31,"area_code":"12","is_voice":0,"flick_time":3,"area_type":1,"warn_name":"10m风","voicecode":"1","warn_type":1,"is_note":1,"status":0},{"warn_pro_id":"S_GUST","is_email":1,"is_flick":1,"maketime":1752339638000,"orderid":37,"area_code":"12","is_voice":1,"flick_time":3,"area_type":1,"warn_name":"阵风","voicecode":"1","warn_type":1,"is_note":1,"status":0},{"warn_pro_id":"S_V","is_email":1,"is_flick":1,"maketime":1752339638000,"orderid":41,"area_code":"12","is_voice":0,"flick_time":3,"area_type":1,"warn_name":"能见度","voicecode":"1","warn_type":1,"is_note":1,"status":0},{"warn_pro_id":"S_H_T","is_email":1,"is_flick":1,"maketime":1752339638000,"orderid":51,"area_code":"12","is_voice":0,"flick_time":3,"area_type":1,"warn_name":"高温","voicecode":"1","warn_type":1,"is_note":1,"status":0},{"warn_pro_id":"S_RADA","is_email":1,"is_flick":1,"maketime":1752339638000,"orderid":121,"area_code":"12","is_voice":1,"flick_time":3,"area_type":1,"warn_name":"雷达回波","voicecode":"1","warn_type":1,"is_note":1,"status":1},{"warn_pro_id":"S_QPE","is_email":1,"is_flick":1,"maketime":1752339638000,"orderid":131,"area_code":"12","is_voice":1,"flick_time":3,"area_type":1,"warn_name":"强降水","voicecode":"1","warn_type":2,"is_note":1,"status":0},{"warn_pro_id":"K_RAIN","is_email":1,"is_flick":1,"maketime":1752339638000,"orderid":141,"area_code":"12","is_voice":1,"flick_time":3,"area_type":1,"warn_name":"短临强降水","voicecode":"1","warn_type":2,"is_note":1,"status":0},{"warn_pro_id":"K_TP3H","is_email":1,"is_flick":1,"maketime":1752339638000,"orderid":151,"area_code":"12","is_voice":1,"flick_time":3,"area_type":1,"warn_name":"短期强降水","voicecode":"1","warn_type":2,"is_note":1,"status":0},{"warn_pro_id":"S_WIND","is_email":1,"is_flick":1,"maketime":1752339638000,"orderid":161,"area_code":"12","is_voice":1,"flick_time":3,"area_type":1,"warn_name":"大风","voicecode":"1","warn_type":2,"is_note":1,"status":0},{"warn_pro_id":"K_GALE","is_email":1,"is_flick":1,"maketime":1752339638000,"orderid":171,"area_code":"12","is_voice":1,"flick_time":3,"area_type":1,"warn_name":"短临大风","voicecode":"1","warn_type":2,"is_note":1,"status":0},{"warn_pro_id":"K_EDA","is_email":1,"is_flick":1,"maketime":1752339638000,"orderid":181,"area_code":"12","is_voice":1,"flick_time":3,"area_type":1,"warn_name":"短期大风","voicecode":"1","warn_type":2,"is_note":1,"status":0},{"warn_pro_id":"K_STORM","is_email":1,"is_flick":1,"maketime":1752339638000,"orderid":191,"area_code":"12","is_voice":1,"flick_time":3,"area_type":1,"warn_name":"雷暴","voicecode":"1","warn_type":2,"is_note":1,"status":0}]};
            if (res.isSuccess && res.data) {
                that.submitFunData = that.cloneObject(res.data);
                for(let i=0;i<res.data.length;i++){
                    var $warn = $("<div><div>警</div><div>"+res.data[i].warn_name+"</div></div>");
                    if(res.data[i].warn_type === 1){
                        $firstObj.append($warn);
                    }else{
                        $secondObj.append($warn);
                    }
                    if(res.data[i].status === 1){
                        $warn.addClass("active");
                    }
                    $warn.unbind("click").bind("click",function () {
                        $(this).toggleClass("active");
                        if($(this).hasClass("active")){
                            that.submitFunData[i]["status"] = 1;
                        }else{
                            that.submitFunData[i]["status"] = 0;
                        }
                    })
                    $(".highLevelBtn.skSet").unbind("click").bind("click",function(){
                        $(".highYbSet").hide();
                        that.openHighLevelPage();
                        if($(this).hasClass("active")){
                            that.submitFunData[i]["status"] = 1;
                        }else{
                            that.submitFunData[i]["status"] = 0;
                        }
                    })
                    $(".highLevelBtn.ybSet").unbind("click").bind("click",function(){
                        $(".highSet").hide();
                        that.openSkHighLevelPage();
                    })
                }
            }
        },
        getWarnSetProduct:function(){
            var that = this;
            var $firstObj = $(".firstWarn .warnContnt");
            $firstObj.empty();
            var $secondObj = $(".secondWarn .warnContnt");
            $secondObj.empty();
            $.getJSON(api.internal.business.getWarnProduct+that.userInfo.smuser.iid, function (res) {
                if (res.isSuccess && res.data) {
                    that.submitFunData = that.cloneObject(res.data);
                    for(let i=0;i<res.data.length;i++){
                        var $warn = $("<div><div>警</div><div>"+res.data[i].warn_name+"</div></div>");
                        if(res.data[i].warn_type === 1){
                            $firstObj.append($warn);
                        }else{
                            $secondObj.append($warn);
                        }
                        if(res.data[i].status === 1){
                            $warn.addClass("active");
                        }
                        $warn.unbind("click").bind("click",function () {
                            $(this).toggleClass("active");
                            if($(this).hasClass("active")){
                                that.submitFunData[i]["status"] = 1;
                            }else{
                                that.submitFunData[i]["status"] = 0;
                            }
                        })
                        $(".highLevelBtn.skSet").unbind("click").bind("click",function(){
                            $(".highYbSet").hide();
                            that.openHighLevelPage();
                            if($(this).hasClass("active")){
                                that.submitFunData[i]["status"] = 1;
                            }else{
                                that.submitFunData[i]["status"] = 0;
                            }
                        })
                        $(".highLevelBtn.ybSet").unbind("click").bind("click",function(){
                            $(".highSet").hide();
                            that.openSkHighLevelPage();
                        })
                    }
                }
            })
        },
        openHighLevelPage:function () {
            var that = this;
            $(".highSet").css("left","450px").css("top","100px");
            $(".highSet").show();
            that.getInitHighData();

            //绑定重置按钮事件
            $(".resetBtn").unbind("click").bind("click",function () {
                that.initSameLevelData(that.defalutData["commonSet"]);
                that.initFirstLevelData(that.defalutData["level"],that.defalutData["userRel1"]);
                that.initSecondLevelData(that.defalutData["level"],that.defalutData["userRel2"]);
            })

            //绑定高级确认按钮事件
            $(".publishBtn").unbind("click").bind("click",function () {
                that.submitHighWarnData();
            })

            $(".highSet .close").unbind("click").bind("click",function () {
                $(".highSet").hide();
            })
            //默认按钮
            $(".defaultBtn").unbind("click").bind("click",function () {
                that.clickDefaultBtn();
            })
        },
        getInitHighData1:function () {
            var that  = this;
            let res = {"isSuccess":true,"message":null,"code":"200","data":{"level":{"S_GALE":[{"areaCode":"12","warnProId":"S_GALE","warnLevel":0,"warnUpperLimit":null,"warnLowerLimit":50.000,"maketime":1469433600000,"areaType":1},{"areaCode":"12","warnProId":"S_GALE","warnLevel":1,"warnUpperLimit":17.000,"warnLowerLimit":50.000,"maketime":1469433600000,"areaType":1},{"areaCode":"12","warnProId":"S_GALE","warnLevel":3,"warnUpperLimit":14.000,"warnLowerLimit":50.000,"maketime":1469433600000,"areaType":1}],"K_EDA":[{"areaCode":"12","warnProId":"K_EDA","warnLevel":0,"warnUpperLimit":null,"warnLowerLimit":17.000,"maketime":1469433600000,"areaType":1}],"S_RAIN1-2":[{"areaCode":"12","warnProId":"S_RAIN1-2","warnLevel":0,"warnUpperLimit":null,"warnLowerLimit":30.000,"maketime":1469433600000,"areaType":2},{"areaCode":"12","warnProId":"S_RAIN1-2","warnLevel":1,"warnUpperLimit":80.000,"warnLowerLimit":25.000,"maketime":1469433600000,"areaType":2},{"areaCode":"12","warnProId":"S_RAIN1-2","warnLevel":3,"warnUpperLimit":50.000,"warnLowerLimit":20.000,"maketime":1469433600000,"areaType":2}],"S_RAIN1-3":[{"areaCode":"12","warnProId":"S_RAIN1-3","warnLevel":0,"warnUpperLimit":null,"warnLowerLimit":30.000,"maketime":1469433600000,"areaType":3},{"areaCode":"12","warnProId":"S_RAIN1-3","warnLevel":1,"warnUpperLimit":80.000,"warnLowerLimit":25.000,"maketime":1469433600000,"areaType":3},{"areaCode":"12","warnProId":"S_RAIN1-3","warnLevel":3,"warnUpperLimit":50.000,"warnLowerLimit":20.000,"maketime":1469433600000,"areaType":3}],"S_GUST":[{"areaCode":"12","warnProId":"S_GUST","warnLevel":0,"warnUpperLimit":null,"warnLowerLimit":17.200,"maketime":1469433600000,"areaType":1},{"areaCode":"12","warnProId":"S_GUST","warnLevel":1,"warnUpperLimit":17.000,"warnLowerLimit":13.900,"maketime":1469433600000,"areaType":1},{"areaCode":"12","warnProId":"S_GUST","warnLevel":3,"warnUpperLimit":14.000,"warnLowerLimit":10.800,"maketime":1469433600000,"areaType":1}],"S_RAIN3-2":[{"areaCode":"12","warnProId":"S_RAIN3-2","warnLevel":0,"warnUpperLimit":null,"warnLowerLimit":100.000,"maketime":1469433600000,"areaType":2},{"areaCode":"12","warnProId":"S_RAIN3-2","warnLevel":1,"warnUpperLimit":80.000,"warnLowerLimit":100.000,"maketime":1469433600000,"areaType":2},{"areaCode":"12","warnProId":"S_RAIN3-2","warnLevel":3,"warnUpperLimit":50.000,"warnLowerLimit":100.000,"maketime":1469433600000,"areaType":2}],"S_RAIN3-3":[{"areaCode":"12","warnProId":"S_RAIN3-3","warnLevel":0,"warnUpperLimit":null,"warnLowerLimit":100.000,"maketime":1469433600000,"areaType":3},{"areaCode":"12","warnProId":"S_RAIN3-3","warnLevel":1,"warnUpperLimit":80.000,"warnLowerLimit":100.000,"maketime":1469433600000,"areaType":3},{"areaCode":"12","warnProId":"S_RAIN3-3","warnLevel":3,"warnUpperLimit":50.000,"warnLowerLimit":100.000,"maketime":1469433600000,"areaType":3}],"S_H_T":[{"areaCode":"12","warnProId":"S_H_T","warnLevel":0,"warnUpperLimit":null,"warnLowerLimit":40.000,"maketime":1469433600000,"areaType":1},{"areaCode":"12","warnProId":"S_H_T","warnLevel":1,"warnUpperLimit":39.000,"warnLowerLimit":39.000,"maketime":1469433600000,"areaType":1},{"areaCode":"12","warnProId":"S_H_T","warnLevel":2,"warnUpperLimit":37.000,"warnLowerLimit":37.000,"maketime":1469433600000,"areaType":1}],"S_GUST-2":[{"areaCode":"12","warnProId":"S_GUST-2","warnLevel":0,"warnUpperLimit":null,"warnLowerLimit":17.200,"maketime":1469433600000,"areaType":2},{"areaCode":"12","warnProId":"S_GUST-2","warnLevel":1,"warnUpperLimit":17.000,"warnLowerLimit":13.900,"maketime":1469433600000,"areaType":2},{"areaCode":"12","warnProId":"S_GUST-2","warnLevel":3,"warnUpperLimit":14.000,"warnLowerLimit":10.800,"maketime":1469433600000,"areaType":2}],"S_GUST-3":[{"areaCode":"12","warnProId":"S_GUST-3","warnLevel":0,"warnUpperLimit":null,"warnLowerLimit":17.200,"maketime":1469433600000,"areaType":3},{"areaCode":"12","warnProId":"S_GUST-3","warnLevel":1,"warnUpperLimit":17.000,"warnLowerLimit":13.900,"maketime":1469433600000,"areaType":3},{"areaCode":"12","warnProId":"S_GUST-3","warnLevel":3,"warnUpperLimit":14.000,"warnLowerLimit":10.800,"maketime":1469433600000,"areaType":3}],"S_RAIN3":[{"areaCode":"12","warnProId":"S_RAIN3","warnLevel":0,"warnUpperLimit":null,"warnLowerLimit":100.000,"maketime":1469433600000,"areaType":1},{"areaCode":"12","warnProId":"S_RAIN3","warnLevel":1,"warnUpperLimit":80.000,"warnLowerLimit":100.000,"maketime":1469433600000,"areaType":1},{"areaCode":"12","warnProId":"S_RAIN3","warnLevel":3,"warnUpperLimit":50.000,"warnLowerLimit":100.000,"maketime":1469433600000,"areaType":1}],"K_GALE":[{"areaCode":"12","warnProId":"K_GALE","warnLevel":0,"warnUpperLimit":null,"warnLowerLimit":17.000,"maketime":1469433600000,"areaType":1}],"S_RAIN1":[{"areaCode":"12","warnProId":"S_RAIN1","warnLevel":0,"warnUpperLimit":null,"warnLowerLimit":30.000,"maketime":1469433600000,"areaType":1},{"areaCode":"12","warnProId":"S_RAIN1","warnLevel":1,"warnUpperLimit":80.000,"warnLowerLimit":25.000,"maketime":1469433600000,"areaType":1},{"areaCode":"12","warnProId":"S_RAIN1","warnLevel":3,"warnUpperLimit":50.000,"warnLowerLimit":20.000,"maketime":1469433600000,"areaType":1}],"K_RAIN":[{"areaCode":"12","warnProId":"K_RAIN","warnLevel":0,"warnUpperLimit":null,"warnLowerLimit":5.000,"maketime":1469433600000,"areaType":1}],"S_RADA":[{"areaCode":"12","warnProId":"S_RADA","warnLevel":0,"warnUpperLimit":null,"warnLowerLimit":50.000,"maketime":1469433600000,"areaType":1},{"areaCode":"12","warnProId":"S_RADA","warnLevel":1,"warnUpperLimit":20.000,"warnLowerLimit":45.000,"maketime":1469433600000,"areaType":1},{"areaCode":"12","warnProId":"S_RADA","warnLevel":2,"warnUpperLimit":15.000,"warnLowerLimit":40.000,"maketime":1469433600000,"areaType":1}],"S_RAIN10M":[{"areaCode":"12","warnProId":"S_RAIN10M","warnLevel":0,"warnUpperLimit":null,"warnLowerLimit":10.000,"maketime":1469433600000,"areaType":1},{"areaCode":"12","warnProId":"S_RAIN10M","warnLevel":1,"warnUpperLimit":80.000,"warnLowerLimit":7.000,"maketime":1469433600000,"areaType":1},{"areaCode":"12","warnProId":"S_RAIN10M","warnLevel":3,"warnUpperLimit":50.000,"warnLowerLimit":5.000,"maketime":1469433600000,"areaType":1}],"K_STORM":[{"areaCode":"12","warnProId":"K_STORM","warnLevel":0,"warnUpperLimit":null,"warnLowerLimit":75.000,"maketime":1469433600000,"areaType":1}],"S_QPE":[{"areaCode":"12","warnProId":"S_QPE","warnLevel":0,"warnUpperLimit":null,"warnLowerLimit":5.000,"maketime":1469433600000,"areaType":1}],"S_V":[{"areaCode":"12","warnProId":"S_V","warnLevel":0,"warnUpperLimit":50.000,"warnLowerLimit":null,"maketime":1469433600000,"areaType":1},{"areaCode":"12","warnProId":"S_V","warnLevel":1,"warnUpperLimit":200.000,"warnLowerLimit":20.000,"maketime":1469433600000,"areaType":1},{"areaCode":"12","warnProId":"S_V","warnLevel":3,"warnUpperLimit":500.000,"warnLowerLimit":50.000,"maketime":1469433600000,"areaType":1}],"S_RADA-3":[{"areaCode":"12","warnProId":"S_RADA-3","warnLevel":0,"warnUpperLimit":null,"warnLowerLimit":50.000,"maketime":1469433600000,"areaType":3},{"areaCode":"12","warnProId":"S_RADA-3","warnLevel":1,"warnUpperLimit":20.000,"warnLowerLimit":45.000,"maketime":1469433600000,"areaType":3},{"areaCode":"12","warnProId":"S_RADA-3","warnLevel":2,"warnUpperLimit":15.000,"warnLowerLimit":40.000,"maketime":1469433600000,"areaType":3}],"S_V-3":[{"areaCode":"12","warnProId":"S_V-3","warnLevel":0,"warnUpperLimit":50.000,"warnLowerLimit":null,"maketime":1469433600000,"areaType":3},{"areaCode":"12","warnProId":"S_V-3","warnLevel":1,"warnUpperLimit":200.000,"warnLowerLimit":20.000,"maketime":1469433600000,"areaType":3},{"areaCode":"12","warnProId":"S_V-3","warnLevel":3,"warnUpperLimit":500.000,"warnLowerLimit":50.000,"maketime":1469433600000,"areaType":3}],"S_RADA-2":[{"areaCode":"12","warnProId":"S_RADA-2","warnLevel":0,"warnUpperLimit":null,"warnLowerLimit":50.000,"maketime":1469433600000,"areaType":2},{"areaCode":"12","warnProId":"S_RADA-2","warnLevel":1,"warnUpperLimit":20.000,"warnLowerLimit":45.000,"maketime":1469433600000,"areaType":2},{"areaCode":"12","warnProId":"S_RADA-2","warnLevel":2,"warnUpperLimit":15.000,"warnLowerLimit":40.000,"maketime":1469433600000,"areaType":2}],"S_V-2":[{"areaCode":"12","warnProId":"S_V-2","warnLevel":0,"warnUpperLimit":50.000,"warnLowerLimit":null,"maketime":1469433600000,"areaType":2},{"areaCode":"12","warnProId":"S_V-2","warnLevel":1,"warnUpperLimit":200.000,"warnLowerLimit":20.000,"maketime":1469433600000,"areaType":2},{"areaCode":"12","warnProId":"S_V-2","warnLevel":3,"warnUpperLimit":500.000,"warnLowerLimit":50.000,"maketime":1469433600000,"areaType":2}],"S_WIND":[{"areaCode":"12","warnProId":"S_WIND","warnLevel":0,"warnUpperLimit":null,"warnLowerLimit":10.000,"maketime":1469433600000,"areaType":1}],"S_H_T-2":[{"areaCode":"12","warnProId":"S_H_T-2","warnLevel":0,"warnUpperLimit":null,"warnLowerLimit":40.000,"maketime":1469433600000,"areaType":2},{"areaCode":"12","warnProId":"S_H_T-2","warnLevel":1,"warnUpperLimit":39.000,"warnLowerLimit":39.000,"maketime":1469433600000,"areaType":2},{"areaCode":"12","warnProId":"S_H_T-2","warnLevel":2,"warnUpperLimit":37.000,"warnLowerLimit":37.000,"maketime":1469433600000,"areaType":2}],"S_H_T-3":[{"areaCode":"12","warnProId":"S_H_T-3","warnLevel":0,"warnUpperLimit":null,"warnLowerLimit":40.000,"maketime":1469433600000,"areaType":3},{"areaCode":"12","warnProId":"S_H_T-3","warnLevel":1,"warnUpperLimit":39.000,"warnLowerLimit":39.000,"maketime":1469433600000,"areaType":3},{"areaCode":"12","warnProId":"S_H_T-3","warnLevel":2,"warnUpperLimit":37.000,"warnLowerLimit":37.000,"maketime":1469433600000,"areaType":3}],"S_GALE-3":[{"areaCode":"12","warnProId":"S_GALE-3","warnLevel":0,"warnUpperLimit":null,"warnLowerLimit":50.000,"maketime":1469433600000,"areaType":3},{"areaCode":"12","warnProId":"S_GALE-3","warnLevel":1,"warnUpperLimit":17.000,"warnLowerLimit":50.000,"maketime":1469433600000,"areaType":3},{"areaCode":"12","warnProId":"S_GALE-3","warnLevel":3,"warnUpperLimit":14.000,"warnLowerLimit":50.000,"maketime":1469433600000,"areaType":3}],"S_GALE-2":[{"areaCode":"12","warnProId":"S_GALE-2","warnLevel":0,"warnUpperLimit":null,"warnLowerLimit":50.000,"maketime":1469433600000,"areaType":2},{"areaCode":"12","warnProId":"S_GALE-2","warnLevel":1,"warnUpperLimit":17.000,"warnLowerLimit":50.000,"maketime":1469433600000,"areaType":2},{"areaCode":"12","warnProId":"S_GALE-2","warnLevel":3,"warnUpperLimit":14.000,"warnLowerLimit":50.000,"maketime":1469433600000,"areaType":2}],"K_TP3H":[{"areaCode":"12","warnProId":"K_TP3H","warnLevel":0,"warnUpperLimit":null,"warnLowerLimit":30.000,"maketime":1469433600000,"areaType":1}],"S_RAIN10M-2":[{"areaCode":"12","warnProId":"S_RAIN10M-2","warnLevel":0,"warnUpperLimit":null,"warnLowerLimit":10.000,"maketime":1469433600000,"areaType":2},{"areaCode":"12","warnProId":"S_RAIN10M-2","warnLevel":1,"warnUpperLimit":80.000,"warnLowerLimit":7.000,"maketime":1469433600000,"areaType":2},{"areaCode":"12","warnProId":"S_RAIN10M-2","warnLevel":3,"warnUpperLimit":50.000,"warnLowerLimit":5.000,"maketime":1469433600000,"areaType":2}],"S_RAIN10M-3":[{"areaCode":"12","warnProId":"S_RAIN10M-3","warnLevel":0,"warnUpperLimit":null,"warnLowerLimit":10.000,"maketime":1469433600000,"areaType":3},{"areaCode":"12","warnProId":"S_RAIN10M-3","warnLevel":1,"warnUpperLimit":80.000,"warnLowerLimit":7.000,"maketime":1469433600000,"areaType":3},{"areaCode":"12","warnProId":"S_RAIN10M-3","warnLevel":3,"warnUpperLimit":50.000,"warnLowerLimit":5.000,"maketime":1469433600000,"areaType":3}]},"commonSet":{"areaCode":"12","voiceCode":"1","flickTime":120,"attentionRadii":100,"subAttentionRadii":null,"warnRadii":50,"subWarnRadii":null,"voiceRadii":120,"noteRadii":4,"emailRadii":null,"noteTime":5,"noteNum":2,"emailTime":null,"emailNum":null,"tophoneTime":null,"maketime":1469433600000,"expend":1,"smsInterval":3},"userRel2":[{"isFlickDefine":null,"isVoiceDefine":1,"areaCode":"12","warnProId":"S_QPE","warnName":"强降水","isVoice":1,"voiceCode":"1","isFlick":1,"isNote":1,"isEmail":1,"flickTime":3,"maketime":1752339638000,"status":0,"orderBy":131,"durTime":null,"isDurTime":null,"areaType":1},{"isFlickDefine":null,"isVoiceDefine":1,"areaCode":"12","warnProId":"K_RAIN","warnName":"短临强降水","isVoice":1,"voiceCode":"1","isFlick":1,"isNote":1,"isEmail":1,"flickTime":3,"maketime":1752339638000,"status":0,"orderBy":141,"durTime":null,"isDurTime":null,"areaType":1},{"isFlickDefine":null,"isVoiceDefine":1,"areaCode":"12","warnProId":"K_TP3H","warnName":"短期强降水","isVoice":1,"voiceCode":"1","isFlick":1,"isNote":1,"isEmail":1,"flickTime":3,"maketime":1752339638000,"status":0,"orderBy":151,"durTime":null,"isDurTime":null,"areaType":1},{"isFlickDefine":null,"isVoiceDefine":1,"areaCode":"12","warnProId":"S_WIND","warnName":"大风","isVoice":1,"voiceCode":"1","isFlick":1,"isNote":1,"isEmail":1,"flickTime":3,"maketime":1752339638000,"status":0,"orderBy":161,"durTime":null,"isDurTime":null,"areaType":1},{"isFlickDefine":null,"isVoiceDefine":1,"areaCode":"12","warnProId":"K_GALE","warnName":"短临大风","isVoice":1,"voiceCode":"1","isFlick":1,"isNote":1,"isEmail":1,"flickTime":3,"maketime":1752339638000,"status":0,"orderBy":171,"durTime":null,"isDurTime":null,"areaType":1},{"isFlickDefine":null,"isVoiceDefine":1,"areaCode":"12","warnProId":"K_EDA","warnName":"短期大风","isVoice":1,"voiceCode":"1","isFlick":1,"isNote":1,"isEmail":1,"flickTime":3,"maketime":1752339638000,"status":0,"orderBy":181,"durTime":null,"isDurTime":null,"areaType":1},{"isFlickDefine":null,"isVoiceDefine":1,"areaCode":"12","warnProId":"K_STORM","warnName":"雷暴","isVoice":1,"voiceCode":"1","isFlick":1,"isNote":1,"isEmail":1,"flickTime":3,"maketime":1752339638000,"status":0,"orderBy":191,"durTime":null,"isDurTime":null,"areaType":1}],"userRel1":[{"isFlickDefine":null,"isVoiceDefine":1,"areaCode":"12","warnProId":"S_RAIN10M","warnName":"10分钟降水","isVoice":1,"voiceCode":"1","isFlick":1,"isNote":1,"isEmail":1,"flickTime":3,"maketime":1752339638000,"status":1,"orderBy":5,"durTime":null,"isDurTime":null,"areaType":1},{"isFlickDefine":null,"isVoiceDefine":1,"areaCode":"12","warnProId":"S_RAIN10M-2","warnName":"10分钟降水","isVoice":1,"voiceCode":"1","isFlick":1,"isNote":1,"isEmail":1,"flickTime":3,"maketime":1752339638000,"status":1,"orderBy":8,"durTime":null,"isDurTime":null,"areaType":2},{"isFlickDefine":null,"isVoiceDefine":1,"areaCode":"12","warnProId":"S_RAIN10M-3","warnName":"10分钟降水","isVoice":1,"voiceCode":"1","isFlick":1,"isNote":1,"isEmail":1,"flickTime":3,"maketime":1752339638000,"status":1,"orderBy":10,"durTime":null,"isDurTime":null,"areaType":3},{"isFlickDefine":null,"isVoiceDefine":1,"areaCode":"12","warnProId":"S_RAIN1","warnName":"1小时降水","isVoice":0,"voiceCode":"1","isFlick":0,"isNote":1,"isEmail":1,"flickTime":3,"maketime":1752339638000,"status":0,"orderBy":11,"durTime":null,"isDurTime":null,"areaType":1},{"isFlickDefine":null,"isVoiceDefine":1,"areaCode":"12","warnProId":"S_RAIN1-2","warnName":"1小时降水","isVoice":0,"voiceCode":"1","isFlick":0,"isNote":1,"isEmail":1,"flickTime":3,"maketime":1752339638000,"status":0,"orderBy":14,"durTime":null,"isDurTime":null,"areaType":2},{"isFlickDefine":null,"isVoiceDefine":1,"areaCode":"12","warnProId":"S_RAIN1-3","warnName":"1小时降水","isVoice":0,"voiceCode":"1","isFlick":0,"isNote":1,"isEmail":1,"flickTime":3,"maketime":1752339638000,"status":0,"orderBy":16,"durTime":null,"isDurTime":null,"areaType":3},{"isFlickDefine":null,"isVoiceDefine":1,"areaCode":"12","warnProId":"S_RAIN3","warnName":"3小时降水","isVoice":0,"voiceCode":"1","isFlick":0,"isNote":1,"isEmail":1,"flickTime":3,"maketime":1752339638000,"status":0,"orderBy":21,"durTime":null,"isDurTime":null,"areaType":1},{"isFlickDefine":null,"isVoiceDefine":1,"areaCode":"12","warnProId":"S_RAIN3-2","warnName":"3小时降水","isVoice":0,"voiceCode":"1","isFlick":0,"isNote":1,"isEmail":1,"flickTime":3,"maketime":1752339638000,"status":0,"orderBy":24,"durTime":null,"isDurTime":null,"areaType":2},{"isFlickDefine":null,"isVoiceDefine":1,"areaCode":"12","warnProId":"S_RAIN3-3","warnName":"3小时降水","isVoice":0,"voiceCode":"1","isFlick":0,"isNote":1,"isEmail":1,"flickTime":3,"maketime":1752339638000,"status":0,"orderBy":26,"durTime":null,"isDurTime":null,"areaType":3},{"isFlickDefine":null,"isVoiceDefine":1,"areaCode":"12","warnProId":"S_GALE","warnName":"10m风","isVoice":0,"voiceCode":"1","isFlick":0,"isNote":1,"isEmail":1,"flickTime":3,"maketime":1752339638000,"status":0,"orderBy":31,"durTime":null,"isDurTime":null,"areaType":1},{"isFlickDefine":null,"isVoiceDefine":1,"areaCode":"12","warnProId":"S_GALE-2","warnName":"10m风","isVoice":0,"voiceCode":"1","isFlick":0,"isNote":1,"isEmail":1,"flickTime":3,"maketime":1752339638000,"status":0,"orderBy":34,"durTime":null,"isDurTime":null,"areaType":2},{"isFlickDefine":null,"isVoiceDefine":1,"areaCode":"12","warnProId":"S_GALE-3","warnName":"10m风","isVoice":0,"voiceCode":"1","isFlick":0,"isNote":1,"isEmail":1,"flickTime":3,"maketime":1752339638000,"status":0,"orderBy":36,"durTime":null,"isDurTime":null,"areaType":3},{"isFlickDefine":null,"isVoiceDefine":1,"areaCode":"12","warnProId":"S_GUST","warnName":"阵风","isVoice":1,"voiceCode":"1","isFlick":1,"isNote":1,"isEmail":1,"flickTime":3,"maketime":1752339638000,"status":0,"orderBy":37,"durTime":null,"isDurTime":null,"areaType":1},{"isFlickDefine":null,"isVoiceDefine":1,"areaCode":"12","warnProId":"S_GUST-2","warnName":"阵风","isVoice":0,"voiceCode":"1","isFlick":1,"isNote":1,"isEmail":1,"flickTime":3,"maketime":1752339638000,"status":0,"orderBy":38,"durTime":null,"isDurTime":null,"areaType":2},{"isFlickDefine":null,"isVoiceDefine":1,"areaCode":"12","warnProId":"S_GUST-3","warnName":"阵风","isVoice":0,"voiceCode":"1","isFlick":1,"isNote":1,"isEmail":1,"flickTime":3,"maketime":1752339638000,"status":0,"orderBy":39,"durTime":null,"isDurTime":null,"areaType":3},{"isFlickDefine":null,"isVoiceDefine":1,"areaCode":"12","warnProId":"S_V","warnName":"能见度","isVoice":0,"voiceCode":"1","isFlick":1,"isNote":1,"isEmail":1,"flickTime":3,"maketime":1752339638000,"status":0,"orderBy":41,"durTime":4,"isDurTime":1,"areaType":1},{"isFlickDefine":null,"isVoiceDefine":1,"areaCode":"12","warnProId":"S_V-2","warnName":"能见度","isVoice":0,"voiceCode":"1","isFlick":1,"isNote":1,"isEmail":1,"flickTime":3,"maketime":1752339638000,"status":0,"orderBy":44,"durTime":4,"isDurTime":1,"areaType":2},{"isFlickDefine":null,"isVoiceDefine":1,"areaCode":"12","warnProId":"S_V-3","warnName":"能见度","isVoice":0,"voiceCode":"1","isFlick":1,"isNote":1,"isEmail":1,"flickTime":3,"maketime":1752339638000,"status":0,"orderBy":46,"durTime":4,"isDurTime":1,"areaType":3},{"isFlickDefine":null,"isVoiceDefine":1,"areaCode":"12","warnProId":"S_H_T","warnName":"高温","isVoice":0,"voiceCode":"1","isFlick":1,"isNote":1,"isEmail":1,"flickTime":3,"maketime":1752339638000,"status":0,"orderBy":51,"durTime":null,"isDurTime":null,"areaType":1},{"isFlickDefine":null,"isVoiceDefine":1,"areaCode":"12","warnProId":"S_H_T-2","warnName":"高温","isVoice":0,"voiceCode":"1","isFlick":1,"isNote":1,"isEmail":1,"flickTime":3,"maketime":1752339638000,"status":0,"orderBy":54,"durTime":null,"isDurTime":null,"areaType":2},{"isFlickDefine":null,"isVoiceDefine":1,"areaCode":"12","warnProId":"S_H_T-3","warnName":"高温","isVoice":0,"voiceCode":"1","isFlick":1,"isNote":1,"isEmail":1,"flickTime":3,"maketime":1752339638000,"status":0,"orderBy":56,"durTime":null,"isDurTime":null,"areaType":3},{"isFlickDefine":null,"isVoiceDefine":1,"areaCode":"12","warnProId":"S_RADA","warnName":"雷达回波","isVoice":1,"voiceCode":"1","isFlick":1,"isNote":1,"isEmail":1,"flickTime":3,"maketime":1752339638000,"status":1,"orderBy":121,"durTime":null,"isDurTime":null,"areaType":1},{"isFlickDefine":null,"isVoiceDefine":1,"areaCode":"12","warnProId":"S_RADA-2","warnName":"雷达回波","isVoice":1,"voiceCode":"1","isFlick":1,"isNote":1,"isEmail":1,"flickTime":3,"maketime":1752339638000,"status":1,"orderBy":124,"durTime":null,"isDurTime":null,"areaType":2},{"isFlickDefine":null,"isVoiceDefine":1,"areaCode":"12","warnProId":"S_RADA-3","warnName":"雷达回波","isVoice":0,"voiceCode":"1","isFlick":1,"isNote":1,"isEmail":1,"flickTime":3,"maketime":1752339638000,"status":1,"orderBy":126,"durTime":null,"isDurTime":null,"areaType":3}]}}
            if (res.isSuccess) {
                that.defalutData = that.cloneObject(res.data);
                that.initSameLevelData(that.defalutData["commonSet"]);
                that.initFirstLevelData(that.defalutData["level"],that.defalutData["userRel1"]);
                that.initSecondLevelData(that.defalutData["level"],that.defalutData["userRel2"]);
                that.submitData = that.cloneObject(res.data);
            }
        },
        getInitHighData:function () {
            var that  = this;
            $.getJSON(api.internal.business.getInitHighData+that.userInfo.smuser.iid, function (res) {
                if (res.isSuccess) {
                    that.defalutData = that.cloneObject(res.data);
                    that.initSameLevelData(that.defalutData["commonSet"]);
                    that.initFirstLevelData(that.defalutData["level"],that.defalutData["userRel1"]);
                    that.initSecondLevelData(that.defalutData["level"],that.defalutData["userRel2"]);
                    that.submitData = that.cloneObject(res.data);
                }
            })
        },
        //对象深复制
        cloneObject:function(obj){
            return JSON.parse(JSON.stringify(obj));
        },
        //切换报警方式
        changeWarnWethod:function(obj,index,level,type){
            obj.toggleClass("active");
            if(obj.hasClass("active")){
                this.submitData[level][index][type] = 1;
            }else{
                this.submitData[level][index][type] = 0;
            }
        },
        initSameLevelData:function (data) {
            var that = this;
            $(".highSet_same input").eq(0).val(data["flickTime"]);
            $(".highSet_same input").eq(0).unbind("change").bind("change",function(){
                that.changeSameLevelData($(this).val(),"flickTime");
            })
            $(".highSet_same input").eq(2).val(data["warnRadii"]);
            $(".highSet_same input").eq(2).unbind("change").bind("change",function(){
                that.changeSameLevelData($(this).val(),"warnRadii");
            })
            $(".highSet_same input").eq(3).val(data["attentionRadii"]);
            $(".highSet_same input").eq(3).unbind("change").bind("change",function(){
                that.changeSameLevelData($(this).val(),"attentionRadii");
            })
            $(".highSet_same input").eq(1).val(data["voiceRadii"]);
            $(".highSet_same input").eq(1).unbind("change").bind("change",function(){
                that.changeSameLevelData($(this).val(),"voiceRadii");
            })
            /*
            $(".highSet_same input").eq(4).val(data["noteRadii"]);
            $(".highSet_same input").eq(4).unbind("change").bind("change",function(){
                that.changeSameLevelData($(this).val(),"noteRadii");
            })
            $(".highSet_same input").eq(5).val(data["smsInterval"]);
            $(".highSet_same input").eq(5).unbind("change").bind("change",function(){
                that.changeSameLevelData($(this).val(),"smsInterval");
            })
            $(".highSet_same select").eq(0).val(data["voiceCode"]);
            $(".highSet_same select").eq(0).unbind("change").bind("change",function(){
                that.changeSameLevelData($(this).val(),"voiceCode");
            })
            */
        },

        initFirstLevelData:function (levelData,data) {
            var that = this;
            var parentObj = $(".firstLevel").eq(0);
            parentObj.empty();
            for(let i=0;i<data.length;i++){
                var obj = $('<div class="singleProduct"></div>');
                parentObj.append(obj);
                var obj1 = $('<div>'+data[i]['warnName']+'</div>');
                obj.append(obj1);
                var obj2 = $('<div></div>');
                var obj2_1 = $('<div></div>');
                obj2.append(obj2_1);
                if(data[i]['warnProId'].indexOf('-') === -1){
                    obj2_1.append('<div>责任区</div>');
                    obj.addClass("level1");
                }
                if(data[i]['warnProId'].indexOf('-2') > 0){
                    obj2_1.append('<div>警戒区</div>');
                    obj.addClass("level2");
                }
                if(data[i]['warnProId'].indexOf('-3') > 0){
                    obj2_1.append('<div>监视区</div>');
                    obj.addClass("level3");
                }
                var obj2_2 = $("<div></div>");
                obj2_1.append(obj2_2);
                obj.append(obj2);

                var obj3 = $("<div></div>");
                var obj3_1 = $("<div></div>");
                obj.append(obj3);
                obj3.append(obj3_1);
                var voiceObj = $('<span class="showtype">声音</span>');
                voiceObj.unbind("click").bind("click",function(){
                    that.changeWarnWethod($(this),i,"userRel1","isVoice");
                });
                var filckObj = $('<span class="showtype">闪烁</span>');
                filckObj.unbind("click").bind("click",function(){
                    that.changeWarnWethod($(this),i,"userRel1","isFlick");
                });
                var noteObj = $('<span class="showtype">短信</span>');
                noteObj.unbind("click").bind("click",function(){
                    that.changeWarnWethod($(this),i,"userRel1","isNote");
                });
                obj3_1.append(voiceObj).append(filckObj)//.append(noteObj);
                if(data[i]["isVoice"] === 1){
                    voiceObj.addClass("active");
                }
                if(data[i]["isFlick"] === 1){
                    filckObj.addClass("active");
                }
                if(data[i]["isNote"] === 1){
                    noteObj.addClass("active");
                }
                that.setWarnFirstLevelByName(levelData,data[i]['warnProId'],data[i]['warnName'],obj2_2);
            }
        },

        initSecondLevelData:function (levelData,data) {
            var that = this;
            var parentObj = $(".secondLevel").eq(0);
            parentObj.empty();
            for(let i=0;i<data.length;i++){
                var obj = $('<div class="singleProduct"></div>');
                parentObj.append(obj);
                var obj1 = $('<div>'+data[i]['warnName']+'</div>');
                obj.append(obj1);
                var obj2 = $('<div></div>');
                var obj2_1 = $('<div></div>');
                obj2.append(obj2_1);
                obj2_1.append('<div></div>');
                var obj2_2 = $("<div></div>");
                obj2_1.append(obj2_2);
                obj.append(obj2);

                var obj3 = $("<div></div>");
                var obj3_1 = $("<div></div>");
                obj.append(obj3);
                obj3.append(obj3_1);
                var voiceObj = $('<span class="showtype">声音</span>');
                voiceObj.unbind("click").bind("click",function(){
                    that.changeWarnWethod($(this),i,"userRel2","isVoice");
                });
                var filckObj = $('<span class="showtype">闪烁</span>');
                filckObj.unbind("click").bind("click",function(){
                    that.changeWarnWethod($(this),i,"userRel2","isFlick");
                });
                var noteObj = $('<span class="showtype">短信</span>');
                noteObj.unbind("click").bind("click",function(){
                    that.changeWarnWethod($(this),i,"userRel2","isNote");
                });
                obj3_1.append(voiceObj).append(filckObj)//.append(noteObj);
                if(data[i]["isVoice"] === 1){
                    voiceObj.addClass("active");
                }
                if(data[i]["isFlick"] === 1){
                    filckObj.addClass("active");
                }
                if(data[i]["isNote"] === 1){
                    noteObj.addClass("active");
                }
                that.setWarnSecondLevelByName(levelData,data[i]['warnProId'],data[i]['warnName'],obj2_2);
            }

        },

        //根据警告名称，设置警告级别
        setWarnFirstLevelByName:function(levelArr,warnProId,warnName,obj){
            var that = this;
            var warnObj = levelArr[warnProId];
            if(warnObj.length === 0){
                obj.append('<div><span>--</span></div>');
            }
            var objSecond = $("<div></div>");
            if(warnName === "10分钟降水" || warnName === "1小时降水" || warnName === "3小时降水" || warnName === "10m风" || warnName === "阵风" || warnName === "高温" || warnName === "雷达回波"){
                var arr = [];
                var obj1_0 = $("<div></div>"); //红
                var obj1_1 = $("<div></div>"); //橙
                var obj1_2 = $("<div></div>"); //黄
                var obj1_3 = $("<div></div>"); //蓝
                var danwei = "mm";
                if(warnName === "10分钟降水" || warnName === "1小时降水" || warnName === "3小时降水"){
                    danwei = "mm";
                }
                if(warnName === "10m风" || warnName === "阵风"){
                    danwei = "m/s";
                }
                if(warnName === "高温"){
                    danwei = "℃";
                }
				if(warnName === "雷达回波"){
                    danwei = "dBZ";
                }
                for(let i=0;i<warnObj.length;i++){
                    if(warnObj[i]["warnLevel"] === 0){
                        obj1_0.append('<span class="redColor">红色</span><span>></span><div><input type="text" value="'+warnObj[i]["warnLowerLimit"]+'"></div><span>'+danwei+'</span>');
                        obj1_0.find("input").bind("change").bind("change",function(){
                            that.submitData["level"][warnProId][i]["warnLowerLimit"] = Number($(this).val());
                        })
                    }
                    if(warnObj[i]["warnLevel"] === 1){
                        obj1_1.append('<span class="orange">橙色</span><span>></span><div><input type="text" value="'+warnObj[i]["warnLowerLimit"]+'"></div><span>'+danwei+'</span>');
                        obj1_1.find("input").bind("change").bind("change",function(){
                            that.submitData["level"][warnProId][i]["warnLowerLimit"] = Number($(this).val());
                        })
                    }
                    if(warnObj[i]["warnLevel"] === 2){
                        obj1_2.append('<span class="yellow">黄色</span><span>></span><div><input type="text" value="'+warnObj[i]["warnLowerLimit"]+'"></div><span>'+danwei+'</span>');
                        obj1_2.find("input").bind("change").bind("change",function(){
                            that.submitData["level"][warnProId][i]["warnLowerLimit"] = Number($(this).val());
                        })
                    }
                    if(warnObj[i]["warnLevel"] === 3){
                        obj1_3.append('<span class="blue">蓝色</span><span>></span><div><input type="text" value="'+warnObj[i]["warnLowerLimit"]+'"></div><span>'+danwei+'</span>');
                        obj1_3.find("input").bind("change").bind("change",function(){
                            that.submitData["level"][warnProId][i]["warnLowerLimit"] = Number($(this).val());
                        })
                    }

                    arr.push(warnObj[i]["warnLevel"]);
                }
                for(var j = arr.length-1;j>=0;j--){
                    if(arr[j] === 3){
                        obj.append(obj1_3);
                    }
                    if(arr[j] === 2){
                        obj.append(obj1_2);
                    }
                    if(arr[j] === 1){
                        obj.append(obj1_1);
                    }
                    if(arr[j] === 0){
                        obj.append(obj1_0);
                    }
                }
            }


            if(warnName === "能见度"){
                var arr = [];
                obj1_0 = $("<div></div>"); //红
                obj1_1 = $("<div></div>"); //橙
                obj1_2 = $("<div></div>"); //黄
                obj1_3 = $("<div></div>"); //蓝
                danwei = "m";
                for(let i=0;i<warnObj.length;i++){
                    if(warnObj[i]["warnLevel"] === 0){
                        obj1_0.append('<span class="redColor">红色</span><span><</span><div><input type="text" value="'+warnObj[i]["warnUpperLimit"]+'"></div><span>'+danwei+'</span>');
                        obj1_0.find("input").bind("change").bind("change",function(){
                            that.submitData["level"][warnProId][i]["warnUpperLimit"] = Number($(this).val());
                        })
                    }
                    if(warnObj[i]["warnLevel"] === 1){
                        obj1_1.append('<span class="orange">橙色</span><span><</span><div><input type="text" value="'+warnObj[i]["warnUpperLimit"]+'"></div><span>'+danwei+'</span>');
                        obj1_1.find("input").bind("change").bind("change",function(){
                            that.submitData["level"][warnProId][i]["warnUpperLimit"] = Number($(this).val());
                        })
                    }
                    if(warnObj[i]["warnLevel"] === 2){
                        obj1_2.append('<span class="yellow">黄色</span><span><</span><div><input type="text" value="'+warnObj[i]["warnUpperLimit"]+'"></div><span>'+danwei+'</span>');
                        obj1_2.find("input").bind("change").bind("change",function(){
                            that.submitData["level"][warnProId][i]["warnUpperLimit"] = Number($(this).val());
                        })
                    }
                    if(warnObj[i]["warnLevel"] === 3){
                        obj1_3.append('<span class="blue">蓝色</span><span><</span><div><input type="text" value="'+warnObj[i]["warnUpperLimit"]+'"></div><span>'+danwei+'</span>');
                        obj1_3.find("input").bind("change").bind("change",function(){
                            that.submitData["level"][warnProId][i]["warnUpperLimit"] = Number($(this).val());
                        })
                    }

                    arr.push(warnObj[i]["warnLevel"]);
                }
                for(var j = arr.length-1;j>=0;j--){
                    if(arr[j] === 3){
                        obj.append(obj1_3);
                    }
                    if(arr[j] === 2){
                        obj.append(obj1_2);
                    }
                    if(arr[j] === 1){
                        obj.append(obj1_1);
                    }
                    if(arr[j] === 0){
                        obj.append(obj1_0);
                    }
                }
            }


            if(warnName === "闪电"){
                objSecond.append('<span>闪电<</span><div><input type="text" value="'+warnObj[0]["warnLowerLimit"]+'"></div><span>KA或闪电></span><div><input type="text" value="'+warnObj[0]["warnUpperLimit"]+'"></div> <span></span>');
                objSecond.find("input").eq(0).bind("change").bind("change",function(){
                    that.submitData["level"][warnProId][0]["warnLowerLimit"] = Number($(this).val());
                })
                objSecond.find("input").eq(1).bind("change").bind("change",function(){
                    that.submitData["level"][warnProId][0]["warnUpperLimit"] = Number($(this).val());
                })
                obj.append(objSecond);
            }
			/*
            if(warnName === "雷达回波"){
                var isDisabled = ['S_RADA-2', 'S_RADA-3'].indexOf(warnProId) != -1 ? 'disabled' : '';
                objSecond.append('<span>雷达回波≥</span><div><input type="text" '+ isDisabled +' value="'+warnObj[0]["warnLowerLimit"]+'"></div><span>dbz</span>');
                objSecond.find("input").eq(0).bind("change").bind("change",function(){
                    that.submitData["level"][warnProId][0]["warnLowerLimit"] = Number($(this).val());
                    $(this).closest('.singleProduct').next().find('input[type=text]').val(Number($(this).val()));
                    $(this).closest('.singleProduct').next().next().find('input[type=text]').val(Number($(this).val()));
                    that.submitData["level"]['S_RADA-2'][0]["warnLowerLimit"] = Number($(this).val());
                    that.submitData["level"]['S_RADA-3'][0]["warnLowerLimit"] = Number($(this).val());
                })
                obj.append(objSecond);
            }
			*/
        },

        setWarnSecondLevelByName:function(levelArr,warnProId,warnName,obj){
            var that = this;
            var warnObj = levelArr[warnProId];
            var objSecond = $("<div></div>");
            if(warnName === "强降水"){
                objSecond.append('<span>降水量></span><div><input type="text" value="'+warnObj[0]["warnLowerLimit"]+'"></div><span>mm</span>');
                objSecond.find("input").eq(0).bind("change").bind("change",function(){
                    that.submitData["level"][warnProId][0]["warnLowerLimit"] = $(this).val();
                })
                obj.append(objSecond);
            }

            if(warnName === "短临强降水"){
                objSecond.append('<span>模式预报30分钟降水></span><div><input type="text" value="'+warnObj[0]["warnLowerLimit"]+'"></div><span>mm</span>');
                objSecond.find("input").eq(0).bind("change").bind("change",function(){
                    that.submitData["level"][warnProId][0]["warnLowerLimit"] = $(this).val();
                })
                obj.append(objSecond);
            }

            if(warnName === "短期强降水"){
                objSecond.append('<span>模式预报3小时降水></span><div><input type="text" value="'+warnObj[0]["warnLowerLimit"]+'"></div><span>mm</span>');
                objSecond.find("input").eq(0).bind("change").bind("change",function(){
                    that.submitData["level"][warnProId][0]["warnLowerLimit"] = $(this).val();
                })
                obj.append(objSecond);
            }

            if(warnName === "大风" && warnProId === "S_WIND"){
                objSecond.append('<span>风速></span><div><input type="text" value="'+warnObj[0]["warnLowerLimit"]+'"></div><span>m/s</span>');
                objSecond.find("input").eq(0).bind("change").bind("change",function(){
                    that.submitData["level"][warnProId][0]["warnLowerLimit"] = $(this).val();
                })
                obj.append(objSecond);
            }
            if(warnName === "短临大风"){
                objSecond.append('<span>风速></span><div><input type="text" value="'+warnObj[0]["warnLowerLimit"]+'"></div><span>m/s</span>');
                objSecond.find("input").eq(0).bind("change").bind("change",function(){
                    that.submitData["level"][warnProId][0]["warnLowerLimit"] = $(this).val();
                })
                obj.append(objSecond);
            }
            if(warnName === "短期大风"){
                objSecond.append('<span>风速></span><div><input type="text" value="'+warnObj[0]["warnLowerLimit"]+'"></div><span>m/s</span>');
                objSecond.find("input").eq(0).bind("change").bind("change",function(){
                    that.submitData["level"][warnProId][0]["warnLowerLimit"] = $(this).val();
                })
                obj.append(objSecond);
            }
            if(warnName === "雷暴"){
                objSecond.append('<span>雷暴概率></span><div><input type="text" value="'+warnObj[0]["warnLowerLimit"]+'"></div><span>%</span>');
                objSecond.find("input").eq(0).bind("change").bind("change",function(){
                    that.submitData["level"][warnProId][0]["warnLowerLimit"] = $(this).val();
                })
                obj.append(objSecond);
            }
        },

        //修改共同预警的数据
        changeSameLevelData:function(value,key){
            var that = this;
            var warnRadiiVal = parseInt($(".highSet_same input").eq(2).val());
            var attentionRadiiVal = parseInt($(".highSet_same input").eq(3).val());
            if(key === "warnRadii"){
                if(warnRadiiVal >= attentionRadiiVal){
                    //alert("警戒区必须小于监视区");
                    return;
                }
            }
            if(key === "attentionRadii"){
                if(warnRadiiVal >= attentionRadiiVal){
                    //alert("监视区必须大于警戒区区");
                    return;
                }
            }
            that.submitData["commonSet"][key] = value;
        },

        //提交高级警告中的数据
        submitHighWarnData:function () {
            var that = this;
            var warnRadiiVal = parseInt($(".highSet_same input").eq(2).val());
            var attentionRadiiVal = parseInt($(".highSet_same input").eq(3).val());
            if(warnRadiiVal >= attentionRadiiVal){
                alert("警戒区必须小于监视区");
                return;
            }
            that.submitData["commonSet"]["warnRadii"] = warnRadiiVal;
            that.submitData["commonSet"]["attentionRadii"] = attentionRadiiVal;
            loading.add('.data-upload');
            $.ajax({
                url: api.internal.business.submitHightWarnData+that.userInfo.smuser.iid,
                type: "POST",
                data: JSON.stringify(that.submitData),
                contentType:'application/json',
                async: false,
                success: function (res) {
                    loading.remove();
                    if(res.isSuccess){
                        alert("保存成功");
                        CafeJS.jcyb.getWarnSet();
                        CafeJS.jcyb.areaExpand();
                        $(".highSet").hide();
                    }else {
                        alert("保存失败");
                    }
                }
            });

            let levelList = [
                {level: 1, warnLevel: 3, levelName: '蓝色'},
                {level: 2, warnLevel: 2, levelName: '黄色'},
                {level: 3, warnLevel: 1, levelName: '橙色'},
                {level: 4, warnLevel: 0, levelName: '红色'}
            ];

            let TP10M = this.submitData.level['S_RAIN10M'].map(el => ({
                element: 'TP10M',
                level: levelList.find(item => item.warnLevel === el.warnLevel).level,
                warnLevel: el.warnLevel,
                levelName: levelList.find(item => item.warnLevel === el.warnLevel).levelName,
                lowVal: el.warnLowerLimit,
                upperVal: el.warnUpperLimit
            }));

            let TP1H = this.submitData.level['S_RAIN1'].map(el => ({
                element: 'TP1H',
                level: levelList.find(item => item.warnLevel === el.warnLevel).level,
                warnLevel: el.warnLevel,
                levelName: levelList.find(item => item.warnLevel === el.warnLevel).levelName,
                lowVal: el.warnLowerLimit,
                upperVal: el.warnUpperLimit
            }));

            let GUSTWS = this.submitData.level['S_GUST'].map(el => ({
                element: 'GUSTWS',
                level: levelList.find(item => item.warnLevel === el.warnLevel).level,
                warnLevel: el.warnLevel,
                levelName: levelList.find(item => item.warnLevel === el.warnLevel).levelName,
                lowVal: el.warnLowerLimit,
                upperVal: el.warnUpperLimit
            }));

            let VIS = this.submitData.level['S_V'].map(el => ({
                element: 'VIS',
                level: levelList.find(item => item.warnLevel === el.warnLevel).level,
                warnLevel: el.warnLevel,
                levelName: levelList.find(item => item.warnLevel === el.warnLevel).levelName,
                lowVal: el.warnLowerLimit,
                upperVal: el.warnUpperLimit
            }));

            let TMP = this.submitData.level['S_H_T'].map(el => ({
                element: 'TMP',
                level: levelList.find(item => item.warnLevel === el.warnLevel).level,
                warnLevel: el.warnLevel,
                levelName: levelList.find(item => item.warnLevel === el.warnLevel).levelName,
                lowVal: el.warnLowerLimit,
                upperVal: el.warnUpperLimit
            }));

            let params = [
                ...TP10M,
                ...TP1H,
                ...GUSTWS,
                ...VIS,
                ...TMP
            ];

            Object.keys(this.autoWarnLevel).forEach(key => {
                if (['TP10M', 'TP1H', 'GUSTWS', 'VIS'].includes(key)) {
                    params.push(this.autoWarnLevel[key].find(el => el.warnLevel === 2));
                }

                if (key === 'TMP') {
                    params.push(this.autoWarnLevel[key].find(el => el.warnLevel === 3));
                }
            });

            $.ajax({
                url: 'shortWarn/autoStation/updateAutoWarnLevel',
                type: 'POST',
                data: JSON.stringify(params),
                contentType:'application/json',
                success: res => {
                    console.log('updateAutoWarnLevel res======>', res);
                    if (res.code === 200) {
                        
                    }
                }
            });
        },

        //提交基础警戒中的数据
        clickSubmitFunData: function () {
            var that = this;
            loading.add('.data-upload');
            var data = {};
            for(var i=0;i<that.submitFunData.length;i++){
                data[that.submitFunData[i]["warn_pro_id"]] = that.submitFunData[i]["status"];
            }
            $.ajax({
                url: api.internal.business.submitFunData+that.userInfo.smuser.iid,
                type: "POST",
                data: JSON.stringify(data),
                contentType:'application/json',
                async: false,
                success: function (res) {
                    loading.remove();
                    if(res.isSuccess){
                        alert("保存成功");
                        $(".highSet").hide();
                    }else {
                        alert("保存失败");
                    }
                }
            })
        },

        //点击默认按钮，页面数据重置
        clickDefaultBtn: function () {
            var that = this;
            $.ajax({
                url: api.internal.business.getInitHighData+that.userInfo.smuser.iid,
                type: "get",
                data: {"areaCode":"default"},
                contentType:'application/json',
                async: false,
                success: function (res) {
                    that.submitData = {};
                    that.initSameLevelData(res.data["commonSet"]);
                    that.initFirstLevelData(res.data["level"],res.data["userRel1"]);
                    that.initSecondLevelData(res.data["level"],res.data["userRel2"]);
                    that.submitData = that.cloneObject(res.data);
                }
            })
        },



        //预报弹框
        openSkHighLevelPage:function () {
            var that = this;
            $(".highYbSet").css("left","450px").css("top","170px");
            $(".highYbSet").show();
            //绑定重置按钮事件
            $(".resetYbBtn").unbind("click").bind("click",function () {
                that.drawGridByData(that.defaultYbData);
            })

            //绑定高级确认按钮事件
            $(".publishYbBtn").unbind("click").bind("click",function () {
                that.submitYbData();
            })

            $(".highYbSet .close").unbind("click").bind("click",function () {
                $(".highYbSet").hide();
            })
            that.initYbData();
        },

        initYbData:function(){
            var that = this;
            loading.add('.data-upload');
            $.ajax({
                url: api.internal.business.getYbWarnData,
                type: "GET",
                data: {},
                contentType:'application/json',
                async: false,
                success: function (res) {
                    loading.remove();
                    if(res.isSuccess && res.data != null){
                        that.setYbData(res.data);
                    }
                }
            })            
        },
        setYbData:function(data){
            var newData = {};
            data.forEach(function(singleData){
                if(newData[singleData.warnId]){
                    newData[singleData.warnId].warnArrs.push({warnLevel:"level"+singleData.warnLevel,warnName:singleData.warnLevelName,warnVal:singleData.warnLimit,obj:singleData});
                }else{
                    newData[singleData.warnId] = {name:singleData.proName,unit:singleData.unit,warnArrs:[{warnLevel:"level"+singleData.warnLevel,warnName:singleData.warnLevelName,warnVal:singleData.warnLimit,obj:singleData}]};
                }
            })
            this.defaultYbData = JSON.parse(JSON.stringify(newData));
            this.drawGridByData(newData);
        },
        drawGridByData:function(data){
            var that = this;
            var $parentObj = $(".singleYbProducts");
            $parentObj.html("");
            for(var key in data){
                var ele = data[key];
                var $singleObj = $("<div class='singleProduct'></div>");
                $singleObj.append("<div>"+ele.name+"</div>");
                $parentObj.append($singleObj);
                var $warnArrParent = $("<div><div><div style='dispaly:none'></div><div></div></div></div>");
                $singleObj.append($warnArrParent);
                ele.warnArrs.forEach(function(warn){
                    warn.warnVal = warn.warnVal == null?'':warn.warnVal;
                    var $warn = $('<div><span class="'+warn.warnLevel+'">'+warn.warnName+'</span><span>≥</span><div><input type="text" value='+warn.warnVal+'></div><span>'+ele.unit+'</span></div>');
                    if(key.toUpperCase().indexOf("SMG") > -1 || key.toUpperCase().indexOf("RAT") > -1){
                        $warn = $('<div><span class="'+warn.warnLevel+'">'+warn.warnName+'</span><span>≥</span><div><input type="text" disabled value='+warn.warnVal+'></div><span></span></div>');
                    }
                    if(key.toUpperCase().indexOf("MDBZ") > -1){
                        $warn = $('<div><span class="'+warn.warnLevel+'">'+warn.warnName+'</span><span>≥</span><div><input type="text" value='+warn.warnVal+'></div><span></span></div>');
                    }
                    if(key.toUpperCase().indexOf("VIS") > -1){
                        $warn = $('<div><span class="'+warn.warnLevel+'">'+warn.warnName+'</span><span>≤</span><div><input type="text" value='+warn.warnVal+'></div><span>'+ele.unit+'</span></div>');
                    }
                    $warn.find("input").data("submitData",warn.obj);
                    $warnArrParent.find(">div >div:nth-child(2)").append($warn);
                })
            } 
        },
        submitYbData:function(){
            var submitData = [];
            var flag = true;
            var obj = {};
            $(".singleYbProducts input").each(function(){
                var val = $(this).val();
                if(val != "" && !/^[0-9]+([.]{1}[0-9]+){0,1}$/.test(val)){
                    alert("请输入数字");
                    obj = $(this);
                    flag = false;
                }
                var singleData = $(this).data("submitData");
                singleData.warnLimit = val;
                submitData.push(singleData);
            })
            if(!flag){
                obj.focus(); 
                return false;
            }
            loading.add('.data-upload');
            $.ajax({
                url: api.internal.business.submitYbWarnData,
                type: "POST",
                contentType: "application/json;charset=utf-8",
                dataType: 'json',
                data: JSON.stringify(submitData),
                success: function (res) {
                    loading.remove();
                    if(res.isSuccess){
                        alert("保存成功");
                        $(".highYbSet").hide();
                    }else {
                        alert("保存失败");
                    }
                }
            })
        }
    };
    if (typeof call === 'function') {
        call(main);
    }
})(function (main) {
    CafeJS.models(['datepicker','modal'], function () {
        main.init();
    });
});
